﻿@model ProductsByTagModel

@using SmartStore.Core.Infrastructure;
@using SmartStore.Web.Models.Catalog;
@using SmartStore.Web;
@using SmartStore.Web.Models.Catalog;

@using SmartStore.Web.Framework.UI;
@using SmartStore.Core.Domain.Seo;

@{
	//title
	Html.AddTitleParts(string.Format(T("PageTitle.ProductsByTag").Text, Model.TagName));
	Html.AddMetaDescriptionParts(string.Format(T("PageTitle.ProductsByTag").Text, Model.TagName));

	//canonical URL
	var canonicalUrlsEnabled = EngineContext.Current.Resolve<SeoSettings>().CanonicalUrlsEnabled;
	if (canonicalUrlsEnabled)
	{
		var byTagUrl = Url.RouteUrl("ProductsByTag", new { productTagId = Model.Id, path = Model.TagName }, this.Request.Url.Scheme);
		Html.AddCanonicalUrlParts(byTagUrl);
	}

	int firstItemIndex = 0;
	int lastItemIndex = 0;
	if (Model.SearchResult.TotalHitsCount > 0)
	{
		firstItemIndex = Model.SearchResult.Hits.FirstItemIndex;
		lastItemIndex = Model.SearchResult.Hits.LastItemIndex;
	}

	Layout = "_Layout";

	ViewBag.HideLeftCol = true; // ...on mobile
}

@if (Model.SearchResult.Facets.Count > 0)
{
	@section left {
		@{ 
			Html.RenderAction("Filters", "Search", new { model = Model });
		}
	}
}

<div class="page product-tag-page">
    <div class="page-title">
		@{ 
			var langAttrs = Html.LanguageAttributes(Model.TagName);
		}
        <h1 class="h3 d-flex align-items-baseline">@Html.Raw(T("Products.Tags.ProductsTaggedWith", "<small " + langAttrs + " class='search-term pl-2'>" + Model.TagName + "</small>"))</h1>
		@if (Model.SearchResult.TotalHitsCount > 0)
		{
			var pageIndex = "<span class='lrm'>{0}-{1}</span>".FormatInvariant(firstItemIndex.ToString("N0"), lastItemIndex.ToString("N0"));
			var pageSize = "<span class='lrm'>" + Model.SearchResult.TotalHitsCount.ToString("N0") + "</span>";
			<h5 class="search-hitcount">@Html.Raw(T("Search.PagingInfo", pageIndex, pageSize))</h5>
		}
    </div>

    <div class="page-body">
        @{ Html.RenderWidget("productsbytag_top"); }

		<div class="product-list-container">
			@if (Model.Products != null)
            {
                Html.RenderPartial("Product.List", Model.Products);
            }
		</div>

		@* TODO: (mc) find more intelligent way of rendering RecentlyViewedProductsBlock globally *@
		@{ Html.RenderAction("RecentlyViewedProductsBlock", "Catalog", new { area = "" }); }

        @{ Html.RenderWidget("productsbytag_bottom"); }
    </div>
</div>
